package org.zecontech.plantvszombie.entity;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.zecontech.plantvszombie.init.ModItems;
import org.zecontech.plantvszombie.util.Helpers;

public class SunFlower extends AbstractPlant {

    private int timer = 60 * 20;

    public SunFlower(EntityType<? extends PathfinderMob> entityType, Level level) {
        super(entityType, level);
    }

    public static AttributeSupplier.Builder createAttributes() {
        return Animal.createAnimalAttributes().add(Attributes.MAX_HEALTH, 10.0);
    }

    @Override
    public void tick() {
        super.tick();
        if (this.level() instanceof ServerLevel serverLevel) {
            this.timer--;
            if (this.timer == 0) {
                serverLevel.addFreshEntity(Helpers.createItemEntity(serverLevel, this.getOnPos(), new ItemStack(ModItems.SUN_ITEM)));
                resetTimer();
            }
        }
    }

    private void resetTimer() {
        this.timer = 60 * 20;
    }
}
